package com.blog.zip.controller.admin;

import com.blog.zip.bean.RespBean;
import com.blog.zip.mapper.CrossMapper;
import lombok.extern.slf4j.Slf4j;

import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class AdminCross {
    @Autowired
    CrossMapper crossMapper;

    @PostMapping("/admin/cross/add")
    public RespBean addCategory(@RequestBody Map<String, Object> payload) {
        long time = System.currentTimeMillis();
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("content", payload.get("cross"));
        m.put("from", payload.get("from"));
        m.put("updated", time);
        m.put("created", time);
        m.put("id", time);
        crossMapper.addCross(m);
        return new RespBean(200, 0, "add success");
    }

    @DeleteMapping("/admin/cross/delete")
    public RespBean deleteCategory(@RequestBody Map<String, Object> payload) {
        String id = (String) payload.get("id");
        crossMapper.deleteCross(id);
        return new RespBean(200, "delete success");
    }

    @GetMapping("/admin/cross/get")
    public RespBean getCategory() {
        List list = crossMapper.getCross();
        Map<String, Object> m = new HashMap<>();
        m.put("crossList", list);
        return new RespBean(200, "success", m);
    }
}
